package org.droid.campus.api.action;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.droid.campus.common.Action;
import org.droid.campus.common.ActionHandler;

public class GetShopCatAction extends Action implements ActionHandler {

	public GetShopCatAction(ServletContext servletContext, String actionName) {
		super(servletContext, actionName);
		// TODO Auto-generated constructor stub
	}

	@Override
	public StringBuffer Do(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		System.out.println("请求参数forword："+request.getParameter("forword"));
		System.out.println("请求参数shopId："+request.getParameter("shopId"));
		StringBuffer sb = new StringBuffer();
		try {
			// System.out.println(request.getServerName()+" "+request.getServerPort()+" "+request.getContextPath());
			URL url = new URL("http://"+request.getServerName()+":8080/"+request.getContextPath()+"/xml/shopcat.xml");
			HttpURLConnection hc = (HttpURLConnection) url.openConnection();
			InputStream is = hc.getInputStream();
		  	BufferedReader read = new BufferedReader(new InputStreamReader(is));
			String str = "";
			while ((str = read.readLine()) != null) {
				sb.append(str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sb;
	}

	@Override
	public boolean prepare(HttpServletRequest request) {
		// TODO Auto-generated method stub
		return true;
	}

}
